package cn.xiaoyuan.service.impl;

import cn.xiaoyuan.dao.UserMapper;
import cn.xiaoyuan.entity.AuthUser;
import cn.xiaoyuan.service.UserAuthService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service
public class UserAuthServiceImpl implements UserAuthService {
    @Resource
    UserMapper userMapper;
    @Override
    public AuthUser getAuthUserByName(String username) {
        return userMapper.getAuthUserByName(username);
    }

    @Override
    public void register(String username,String password,Integer roleId,String realName,String tel) {
        AuthUser authUser=new AuthUser().setId(0).setUsername(username).setPassword(password).setRoleId(roleId);
        System.out.println(authUser);
        if(userMapper.register(authUser) < 0){
            throw new RuntimeException("用户账号注册失败");
        }
        if (userMapper.addrealusers(authUser.getId(), realName, tel)<0) {
            throw new RuntimeException("用户基本信息添加失败");
        }
    }
    @Override
    public Integer getRoleIdByName(String roleName) {
        return userMapper.getRoleIdByName(roleName);
    }

    @Override
    public String getRoleNameByRoleId(Integer roleId) {
        return userMapper.getRoleNameByRoleId(roleId);
    }

    @Override
    public String getTel(String tel) {
        return userMapper.getTel(tel);
    }
}
